package com.sl.crawler.common.utils.thread;

import com.sl.crawler.common.utils.random.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by shiling on 2017/6/3.
 */
public class ThreadUtils {
    private static Logger LOG = LoggerFactory.getLogger(ThreadUtils.class);

    /**
     * 睡眠9秒
     */
    public static void sleepSecond10() {
        int sleepSecond = 10;
        sleepSecond = sleepSecond + RandomUtils.getnextInt(sleepSecond);
        sleepMillisecond(sleepSecond * 1000);
    }

    /**
     * 按秒睡眠
     *
     * @param second
     */
    public static void sleepSecond(int second) {
        sleepMillisecond(second * 1000);
    }

    /**
     * 按照毫秒睡眠
     *
     * @param millisecond
     */
    public static void sleepMillisecond(int millisecond) {
        try {
            Thread.sleep(millisecond);
        } catch (InterruptedException e) {
            LOG.error("睡眠" + millisecond + "豪秒失败!", e);
        }
    }
}
